package com.ms.game.slot.base;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.xpec.c4.db.hibernate.manager.HibernateManager;
import com.xpec.c4.db.model.basic.BasicGameModel;

public class SlotWaterDisappearSystem<T> {
	/**
	 * 讀取空機台
	 * @param name
	 * @return
	 */
	public List<T> getStateEmpty(String name)
	{
		Session session  = HibernateManager.txBegin();
		
		Query query = session.createQuery("From "+name+" Where seatstat in(:STAT,:STAT1,:STAT2) and CONV(waterpool,19,2) >:VALUE");
		query.setInteger("STAT", BasicGameModel.EMPTY);
		query.setInteger("STAT1", BasicGameModel.KEEP);
		query.setInteger("STAT2", BasicGameModel.OFFLINE_KEEP);
		query.setInteger("VALUE", 0);
		
		return (List<T>)query.list();
	}
	
	/**
	 * 讀取非為空的機台
	 * @param name
	 * @return
	 */
	public List<T> getStateNotEmtpy(String name)
	{
		Session session  = HibernateManager.txBegin();
		Query query = session.createQuery("Select db_id From "+name+" Where seatstat>:STAT and CONV(waterpool,19,2) >:VALUE");
		query.setInteger("STAT", BasicGameModel.EMPTY);
		query.setInteger("VALUE", 0);
		
		return (List<T>)query.list();
	}
	
	/**
	 * 更新資料庫資料
	 * @param model
	 * @return
	 */
	public boolean modifyModel(T model)
	{
		Session session = HibernateManager.txBegin();
		session.saveOrUpdate(model);
		return HibernateManager.txCommitFailRollbackClearSession();
	}
}
